package other.refereance;

import java.lang.ref.SoftReference;

//软引用适合做缓存

public class T02_SoftReference {

    public static void main(String[] args) throws InterruptedException {
        SoftReference<byte[]> m = new SoftReference<>(new byte[1024 * 1024*10]);

        System.out.println(m.get());

        System.gc();
        Thread.sleep(500);
        System.out.println(m.get());
        /*
        这里设置虚拟机栈内存为20M，执行下面语句后内存就不够了，需要回收堆内存
        于是m里面的堆内存就被回收了
         */
        byte[] b = new byte[1024 * 1024 * 15];
        System.out.println(m.get());
    }
}
